"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var api_1 = require("../../../config/api");
var http_1 = require("@angular/http");
var Observable_1 = require("rxjs/Observable");
var DisplayService = /** @class */ (function () {
    function DisplayService(httpService, localStorageService) {
        var _this = this;
        this.httpService = httpService;
        this.localStorageService = localStorageService;
        this.list = [];
        this.IdObservable = Observable_1.Observable
            .create(function (observer) {
            observer.next(_this.id);
        });
    }
    //初始化
    DisplayService.prototype.initInfo = function (pointer, booth) {
        switch (booth) {
            case 'a':
                this.boothA(pointer);
                break;
            case 'b':
                this.boothB(pointer);
                break;
            case 'c':
                this.boothC(pointer);
                break;
        }
    };
    DisplayService.prototype.boothA = function (pointer) {
        pointer.picSizeInfo = '图片尺寸: 710 * 330px';
        pointer.previewTitle = '首页轮播展示图';
        pointer.previewsubTitle = '可用于活动、商品推广，图片数量（0/3)';
        pointer.previewSrc = 'banner_view';
        pointer.options = [
            { value: 'picture', label: '图片' },
            { value: 'product', label: '商品' },
            { value: 'coupons', label: '卡券' },
            { value: 'activity', label: '活动' },
            { value: 'page', label: '页面' }
        ];
    };
    DisplayService.prototype.boothB = function (pointer) {
        pointer.picSizeInfo = '图片尺寸: 750 * 232px';
        pointer.previewTitle = '商品推荐展示图';
        pointer.previewsubTitle = '用于商品宣传推广';
        pointer.previewSrc = 'special_view';
        pointer.options = [
            { value: 'product', label: '商品' },
            // {value: 'coupons', label: '卡券'},
            { value: 'activity', label: '活动' },
        ];
    };
    DisplayService.prototype.boothC = function (pointer) {
        pointer.picSizeInfo = '图片尺寸: 220 * 250px';
        pointer.previewTitle = '拼团展示图';
        pointer.previewsubTitle = '可用于拼团、抽奖商品推广';
        pointer.previewSrc = 'group_view';
        pointer.options = [{ value: 'picture', label: '图片' }];
        pointer.selectedOption = pointer.options[0];
    };
    DisplayService.prototype.getCaseDetailList = function (showCaseId, index) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            _this.getShowCaseDetailList(showCaseId).subscribe(function (res) {
                if (res.code === 2000) {
                    var detailList = _this.list[index ? index : _this.showCaseIndex]['detailList'] = res.data.data;
                    detailList.map(function (e, i) {
                        e['edit'] = false;
                    });
                    var id = detailList.length != 0 ? detailList[0]['id'] : null;
                    resolve(id);
                }
                else {
                    reject();
                }
            });
        });
    };
    //获取橱窗列表
    DisplayService.prototype.getShowCaseList = function (templateId) {
        var url = api_1.adSystemApiUrl + "/v1/member/show_case/list/?order={\"sort\":\"asc\"}&template_id=" + templateId;
        return this.httpService.httpGetAuth(url).map(function (res) { return res; });
    };
    //根据showcaseId获取橱窗详情列表
    DisplayService.prototype.getShowCaseDetailList = function (showcaseId) {
        var url = api_1.adSystemApiUrl + "/v1/member/show_case_detail/list?order={\"sort\":\"asc\"}&showcase_id=" + showcaseId + "&pageSize=999";
        return this.httpService.httpGetAuth(url).map(function (res) { return res; });
    };
    //根据showcaseId获取橱窗详情列表分页
    DisplayService.prototype.getShowCaseDetailCutList = function (showcaseId, page, pageSize, order, name) {
        var url = api_1.adSystemApiUrl + "/v1/member/show_case_detail/list?order=" + order + "&showcase_id=" + showcaseId + "&name=" + name + "&page=" + page + "&pageSize=" + pageSize;
        return this.httpService.httpGetAuth(url).map(function (res) { return res; });
    };
    //获取活动列表
    DisplayService.prototype.getActivityList = function (page, pageSize, keyWord, type, stage, status) {
        var url = api_1.adSystemApiUrl + "/v3/member/activity/list?page=" + page + "&pageSize=" + pageSize + "&keyword=" + keyWord + "&type=" + type + "&stage=" + stage + "&status=" + status + "&order_by={\"start_date\":\"desc\",\"created_at\":\"desc\"}";
        return this.httpService.httpGetAuth(url).map(function (res) { return res; });
    };
    //获取活动商品列表
    DisplayService.prototype.getActivityGoodsList = function (activityId, activityGoodsId) {
        var url = api_1.adSystemApiUrl + "/v3/member/activity_goods/get_goods?activity_id=" + activityId + "&activity_goods_id=" + activityGoodsId;
        return this.httpService.httpGetAuth(url).map(function (res) { return res; });
    };
    //获取卡券列表
    DisplayService.prototype.getCouponList = function (page, pageSize, keyWord) {
        var url = api_1.adSystemApiUrl + "/v2/member/card_coupons/list";
        var headers = new http_1.Headers({ 'Content-Type': 'application/json' });
        var options = new http_1.RequestOptions({ headers: headers });
        var body = JSON.stringify({
            'applet_uuid': this.localStorageService.getNowApplet()['applet_uuid'],
            'page': page,
            'pageSize': pageSize,
            'keyword': keyWord
        });
        return this.httpService.httpPostAuth(url, body, options).map(function (res) { return res; });
    };
    //添加展位单元
    DisplayService.prototype.addShowCase = function (data) {
        var url = api_1.adSystemApiUrl + "/v1/member/show_case_detail/add_v3";
        var headers = new http_1.Headers({ 'Content-Type': 'application/json' });
        var options = new http_1.RequestOptions({ headers: headers });
        var body = data;
        body['applet_uuid'] = this.localStorageService.getNowApplet()['applet_uuid'];
        return this.httpService.httpPostAuth(url, body, options).map(function (res) { return res; });
    };
    DisplayService.prototype.getShowCaseDetailInfo = function (id) {
        var token = this.localStorageService.getToken()['access_token'];
        var url = api_1.adSystemApiUrl + "/v1/member/show_case_detail/" + id + "/info?token=" + token;
        return this.httpService.httpGetAuth(url).map(function (res) { return res; });
    };
    //获取商品详情
    DisplayService.prototype.getGoodsDetail = function (id) {
        var url = api_1.adSystemApiUrl + "//v1/applet/goods/get_goods_info_v2?id=" + id;
        return this.httpService.httpGetAuth(url).map(function (res) { return res; });
    };
    //修改展位详情
    DisplayService.prototype.editShowCaseDetail = function (data) {
        var url = api_1.adSystemApiUrl + "/v1/member/show_case_detail/edit";
        var headers = new http_1.Headers({ 'Content-Type': 'application/json' });
        var options = new http_1.RequestOptions({ headers: headers });
        var body = data;
        body['applet_uuid'] = this.localStorageService.getNowApplet()['applet_uuid'];
        return this.httpService.httpPostAuth(url, body, options).map(function (res) { return res; });
    };
    //展位删除
    DisplayService.prototype.delShowCaseDetail = function (id) {
        var url = api_1.adSystemApiUrl + "/v1/member/show_case_detail/" + id + "/del";
        return this.httpService.httpPostAuth(url, {}).map(function (rs) { return rs; });
    };
    DisplayService = __decorate([
        core_1.Injectable()
    ], DisplayService);
    return DisplayService;
}());
exports.DisplayService = DisplayService;
